'use strict';

module.exports = app => {
  const { STRING, INTEGER, DATE,ENUM } = app.Sequelize;

  const Dictionary = app.model.define('dictionary', {
    id: { type: INTEGER, primaryKey: true, autoIncrement: true },
    dict_key: { type: STRING(255), allowNull: false },
    dict_value: { type: STRING(255), allowNull: false },
    icon: STRING(255),
    dict_type:  ENUM('business','system'),
    description: STRING(255),
    created_at: DATE,
    updated_at: DATE,
  }, {
    tableName: 'dictionary',
    timestamps: true,
    indexes: [
      {
        unique: true,
        fields: ['dict_key', 'dict_type'],
      },
    ],
  });

  Dictionary.associate = function() {
    app.model.Dictionary.hasMany(app.model.DictionaryDetail, { foreignKey: 'parent_id' });
  };

  return Dictionary;
};
